package com.wh.controller;


import java.util.List;

import javax.annotation.Resource;

import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.wh.pojo.EuiccCard;
import com.wh.pojo.EuiccProfile;
import com.wh.repository.EuiccCardRepo;
import com.wh.repository.EuiccProfileRepo;

@RestController
@RequestMapping("/euicc-app")
public class EuiccAppController {
	@Resource
	private EuiccCardRepo cardRepo;
	
	@Resource
	private EuiccProfileRepo profileRepo;
	
	/**
	 * 查询card列表
	 * @param eid
	 * @return
	 * http://localhost:8080/spring-jpa-demo/euicc-app/queryCard
	 * http://localhost:8080/spring-jpa-demo/euicc-app/queryCard?eid=123456
	 */
	@RequestMapping("/queryCard")
	public Object queryCard(@RequestParam(required = false) String eid){
		if(StringUtils.isEmpty(eid)){
			return cardRepo.findAll();
		}
		EuiccCard card = cardRepo.findOne(eid);
		return card;
	}
	
	/**
	 * 查询下载安装profile（启用、禁用、删除）
	 * @param eid
	 * @return
	 * http://localhost:8080/spring-jpa-demo/euicc-app/queryInstallProfile/89001012012341234012345678901224
	 */
	@RequestMapping("/queryInstallProfile/{eid}")
	public List<EuiccProfile> queryInstallProfile(@PathVariable String eid){
		return profileRepo.findInstallByEid(eid);
		
	}
	
	/**
	 * 查询管理profile（启用、禁用、删除）
	 * @param eid
	 * @return
	 * http://localhost:8080/spring-jpa-demo/euicc-app/queryMgrProfile/89001012012341234012345678901224
	 */
	@RequestMapping("/queryMgrProfile/{eid}")
	public List<EuiccProfile> queryMgrProfile(@PathVariable String eid){
		return profileRepo.findByEid(eid);
		
	}
	
	

}
